import httpRequest from "./http.request";
import config from "./config";

const apiPre = "/merchants/multistores/";
const weixinApiPre = "/merchants/weixin/";
const platformApiPre = "";
const apiServiceName = "/api/small_merchant_api_service";

export const loadServiceBySiUuid = async (siUuid, orUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getServiceItemBySiUuid",
            data: {
                siUuid,
                orUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const loadCommodityByCiUuid = async (ciUuid, orUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getCommodityByCiUuid",
            data: {
                ciUuid,
                orUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const loadDiscountByDpUuid = async (dpUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getDiscountByDpUuid",
            data: {
                dpUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getDailyHomePage = async (orUuid, scName) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getDailyHomePage",
            data: {
                orUuid,
                scName
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getOnlineRetailerID = async (orApid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getOnlineRetailerID",
            data: {
                orApid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getDailyCategoryPage = async (orUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/miniapp/getDailyCategoryPage",
            data: {
                orUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getCaregoryCommodity = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/shopping_mall/getCaregoryCommodity",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getCaregoryService = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "daily/shopping_mall/getCaregoryService",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getActivityHomeData = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "weixin/miniapp/getActivityHomePage",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getActivityItemDetailPage = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "weixin/miniapp/getActivityItemDetailPage",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getStaffHomePage = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "weixin/miniapp/getStaffHomePage",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getConsumerHomePage = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
           apiPath: apiPre + "weixin/miniapp/getConsumerHomePage",
           data
        },
        object: "organization",
    });
    return res || {};
};

export const getActivity = async () => {
    let res = await httpRequest({
        url: "/api/v1/groupPurchaseActivities/merchants/getByMcUuid",
        data: {
            mcUuid: config.organizationUuid,
        },
        object: "platform",
    });
    return res?.gpUuid ? res : {};
};

export const getActivityByGpUuid = async (gpUuid) => {
    let res = await httpRequest({
        url: "/api/v1/groupPurchaseActivities/groupPurchaseActivities/getByGpUuid",
        data: {
            gpUuid,
        },
        object: "platform",
    });
    return res || {};
};

// 创建客户关系
export const createCustomerLoginRelationship = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/createCustomerLoginRelationship",
            data
        },
        object: "organization",
        showError: false,
    });
    return res;
};

// 获取电话
export const getWxPhoneNumber = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: weixinApiPre + "miniapp/getWxPhoneNumber",
            data
        },
        object: "organization",
    });
};

// 获取客户信息，通过电话
export const getCustomerByCiPhon = async (data) => {
    return (
        (await httpRequest({
            url: apiServiceName,
            data: {
                apiPath: apiPre + "consumer/getCustomerByCiPhon",
                data
            },
            object: "organization",
        })) || {}
    );
};

// 创建客户信息
export const createCustomers = async (data) => {
    return (
        (await httpRequest({
            url: apiServiceName,
            data: {
                apiPath: apiPre + "consumer/createCustomerAndMiniApp",
                data
            },
            object: "organization",
        })) || {}
    );
};

export const createPlatformConsumerInfo = async (data) => {
    return await httpRequest({
        url: "/api/v1/groupPurchaseActivities/merchants/createConsumerInfo",
        data,
        object: "platform",
    });
};

// 更新客户信息
export const updateCustomerByCiUuid = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/updateCustomerByCiUuidAndCreateMiniApp",
            data
        },
        object: "organization",
    });
};

// 更新客户真实姓名
export const updateCustomerCiNameByCiUuid = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/updateCustomerCiNameByCiUuid",
            data
        },
        object: "organization",
    });
};

// 合并游客信息到客户信息
export const mergeGuestToCustomer = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/functionMergeUpdateBrowse",
            data
        },
        object: "organization",
    });
};

export const getItemAppointmentByGaApid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/getItemAppointmentByGaApid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const createItemAppointment = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/createItemAppointment",
            data
        },
        object: "organization",
    });
};

export const createStaffFission = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/createStaffFission",
            data
        },
        object: "organization",
    });
};

export const createCustomerFission = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/createCustomerFission",
            data
        },
        object: "organization",
    });
};

export const getActivityItemSpellOrder = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/getItemSpellOrder",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustOrderBySoCuidAndSoItem = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/getCustOrderBySoCuidAndSoItem",
            data
        },
        object: "organization",
    });
    return res?.a || [];
};

// 检查订单客户是否为团长
export const checkGroupLeader = async (data) => {
    return (
        (await httpRequest({
            url: apiServiceName,
            data: {
                apiPath: apiPre + "consumer/activity/checkGroupLeader",
                data
            },
            object: "organization",
        })) || {}
    );
};

export const createActivityItemsOrder = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/createActivityItemsOrder",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const updateActivityItemSpellOrder = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/updateItemSpellOrder",
            data
        },
        object: "organization",
    });
};

export const createActivityItemSpellOrder = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/createItemSpellOrder",
            data
        },
        object: "organization",
    });
};

export const getOrderByCiUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/getOrderByCiUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

// 获取项目奖励
export const getItemRebateByCiUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/getItemRebateByCiUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getMyCustomerAppointment = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getMyCustomerAppointment",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getOrdersByOrUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getOrdersByOrUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerGroupByOrUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerGroupByOrUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const cancelOrder = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/cancelOrderBySoUuid",
            data
        },
        object: "organization",
    });
};

export const deleteOrder = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/deleteOrderBySoUuid",
            data
        },
        object: "organization",
    });
};

export const getSharePersonGroupByGmUuid = async (soScid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/getSharePersonGroupByGmUuid",
            data:{
                gmUuid: soScid,
            }
        },
        object: "organization",
    });
    return res || [];
};

// 待支付订单
export const waitingPayOrderPay = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/order/waitingPayOrderPay",
            data
        },
        object: "organization",
    });
};

// 获取小程序码
export const getWxCode = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: weixinApiPre + "miniapp/getWxCode",
            data
        },
        object: "organization",
    });
};

export const getStaffRanks = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getStaffRank",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getCustomerRanks = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerRank",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getItemRanks = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getItemRank",
            data
        },
        object: "organization",
    });
    return res || {};
};

// 获取微信用户认证
export const getPhoneAuthCode = async (data) => {
    return await httpRequest({
        url: "/api/authcode/getPhoneAuthCode",
        data,
        object: "platform",
    });
};

export const loginByPhone = async (data) => {
    return await httpRequest({
        url: "/api/member/loginByPhone",
        data,
        object: "platform",
    });
};

// 待确认
export const getStaffByOmUuid = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getStaffByOmUuid",
            data
        },
        object: "organization",
    });
};

export const getMyCustomerInfo = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getMyCustomerInfo",
            data
        },
        object: "organization",
    });
    return res || [];
};

// 用户浏览记录
export const getMyCustomerBrowse = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getMyCustomerBrowse",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const createActivityBrowse = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/createActivityBrowse",
            data
        },
        object: "organization",
        showError: false,
    });
};

export const updateActivityBrowse = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/updateActivityBrowse",
            data
        },
        object: "organization",
        showError: false,
    });
};

export const getItemSpellOrderByGgUuid = async (ggUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/activity/getItemSpellOrderByGgUuid",
            data: {
                ggUuid,
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getCustomerByOpenId = async (openId) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/getCustomerByOpenId",
            data: {
                openId,
            }
        },
        object: "organization",
    });
};

export const getCustomerServiceItemList = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerServiceItemList",
            data
        },
        object: "organization",
    });
};

export const getCustomers = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomers",
            data
        },
        object: "organization",
    });
};

export const createCustomerServiceItemList = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/createCustomerServiceItemList",
            data
        },
        object: "organization",
    });
};

export const getCustomerPendingServiceItem = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerPendingServiceItem",
            data
        },
        object: "organization",
    });
};

export const createCurrentServiceItem = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/createCurrentServiceItem",
            data
        },
        object: "organization",
    });
};

export const getStaffAll = async () => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getStaffAll",
            data: {}
        },
        object: "organization",
    });
};

export const updateCurrentServiceItem = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/updateCurrentServiceItem",
            data
        },
        object: "organization",
    });
};

export const deleteCurrentServiceItem = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/deleteCurrentServiceItem",
            data
        },
        object: "organization",
    });
};

export const getServiceItemQuant = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustServiceItemQuantBySiUuidAndCiUuid",
            data
        },
        object: "organization",
    });
};

export const submitServiceOrder = async (data) => {
    return await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/submitServiceOrder",
            data
        },
        object: "organization",
    });
};

export const getActivityStores = async (gpUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getActivityStores",
            data: {
                gpUuid, 
            }
        },
        object: "organization",
    });
    return res?.nodes || [];
};

export const getBossHomePage = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "weixin/miniapp/getBossHomePage",
            data
        },
        object: "organization",
    });
    return res || {};
};

export const getCustomerCurrentServiceItem = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerCurrentServiceItem",
            data
        },
        object: "organization",
    });
    return res;
};

export const getMyServedCustomerServiceItemList = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getMyServedCustomerServiceItemList",
            data
        },
        object: "organization",
    });
    return res;
};

export const getMyServiceItemList = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/getMyServiceItemList",
            data
        },
        object: "organization",
    });
    return res;
};

export const updateMyCurrentServiceItem = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/updateMyCurrentServiceItem",
            data
        },
        object: "organization",
    });
    return res;
};

export const custSubmitServiceOrder = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/custSubmitServiceOrder",
            data
        },
        object: "organization",
    });
    return res;
};

export const getMyServiceItemSource = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "consumer/getMyServiceItemSource",
            data
        },
        object: "organization",
    });
    return res;
};

export const getAllCustomerInfo = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getAllCustomerInfoByOsUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerBrowse = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerBrowse",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerByFission = async (osUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerByFission",
            data: {
                osUuid
            }
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerRelationship = async (ciUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerRelationship",
            data: {
                ciUuid
            }
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerByCiUuid = async (ciUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerByCiUuid",
            data: {
                ciUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getStaffByOrUuid = async (orUuid) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getStaffByOrUuid",
            data: {
                orUuid
            }
        },
        object: "organization",
    });
    return res || {};
};

export const getOrdersByOsUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getOrdersByOsUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getAllStaffFissionByOsUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getStaffFissionByOsUuidAndOsUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerRelationshipByOrUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerRelationshipByOrUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerOrdersByOrUuidAndGpUuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerOrdersByOrUuidAndGpUuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getCustomerAppointment = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getCustomerAppointment",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getStoreRanks = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "boss/getStoreFission",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getAppointmentByGaCuid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getCustomerAppointmentByGaCuid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getOrdersBySoScid = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getOrdersBySoScid",
            data
        },
        object: "organization",
    });
    return res || [];
};

export const getMyCustomerRelationship = async (data) => {
    let res = await httpRequest({
        url: apiServiceName,
        data: {
            apiPath: apiPre + "staff/getMyCustomerRelationship",
            data
        },
        object: "organization",
    });
    return res || [];
};
